check host CONSUL-DNS with address 127.0.0.1
  if failed
    port 53
  then exec "/usr/sbin/service consul-dns start"

check host CHRONY with address {{ bind_address }}
  start program = "/usr/sbin/service chronyd start"
  stop program = "/usr/sbin/service chronyd stop"
  if failed
    port 123
    type udp
    for 5 cycles
  then restart

check host CONSUL with address {{ bind_address }}
  start program = "/usr/sbin/service consul start"
  stop program = "/usr/sbin/service consul stop"
  if failed port 8600 for 5 cycles then restart
  if failed port 8301 for 5 cycles then restart

{% if 'logstash' in group_names %}
check host LOGSTASH with address 127.0.0.1
  start program = "/usr/sbin/service logstash start"
  stop program = "/usr/sbin/service logstash stop"
  if failed
    port 9600
    for 10 cycles
  then alert
{% endif %}

{% if 'kibana' in group_names %}
check host KIBANA with address {{ bind_address }}
  start program = "/usr/sbin/service kibana start"
  stop program = "/usr/sbin/service kibana stop"
  if failed
    port {{ kibana_port }}
    for 10 cycles
  then alert

check file KIBANA-LOG with path /var/log/kibana/kibana.log
  start program = "/usr/sbin/service kibana start"
  stop program = "/usr/sbin/service kibana stop"
  if content != ".*getaddrinfo ENOTFOUND.*" for 10 cycles
  then alert

check host ES-SHARDS-STATUS with address ingest.elastic.service.{{ consul_dc_name }}.consul
  if failed
    port 9200
    protocol http
    request "/_cat/shards"
    content != "UNASSIGNED"
    for 10 cycles
  then alert
{% endif %}

{% if 'elasticsearch' in group_names %}
check host ELASTICSEARCH with address {{ bind_address }}
  start program = "/usr/sbin/service elasticsearch start"
  stop program = "/usr/sbin/service elasticsearch stop"
  if failed port {{ elastic_http_port }} for 10 cycles then alert
{% endif %}

{% if 'redis' in group_names %}
check host REDIS-SERVER with address {{ bind_address }}
  start program = "/usr/sbin/service redis-server start"
  stop program = "/usr/sbin/service redis-server stop"
  if failed port 6379 protocol redis for 10 cycles then alert

check host REDIS-SENTINEL with address {{ bind_address }}
  start program = "/usr/sbin/service redis-sentinel start"
  stop program = "/usr/sbin/service redis-sentinel stop"
  if failed port 26379 for 10 cycles then alert

check host REDIS-MASTER with address redis.service.{{ consul_dc_name }}.consul
  if failed port 6379 for 10 cycles then alert
{% endif %}
